# -*- coding: utf-8 -*-

from flask.ext.login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from . import login_manager
import leancloud
leancloud.init("po7YWHB3bjxCwOkLEyBbO0Y6-gzGzoHsz", "NkA8kxpPmtK3NHwgy6vVBls0")

class User(UserMixin):

	def __init__(self, query):
		self.user_id = query.get('f_u_id')
		self.username = query.get('f_u_name')
		self.password = query.get('f_u_password')

	def get_id(self):
		return self.user_id

	def is_authenticated(self):
		return True

	def is_active(self):
		return True

	def is_anonymous(self):
		return True


@login_manager.user_loader
def load_user(user_id):
	FUser = leancloud.Object.extend('FUser')
	query = FUser.query
	query.equal_to('f_u_id', int(user_id))
	query_list = query.find()
	if len(query_list) == 0:
		return None
	else:
		return User(query_list[0])

		